/*
 * @Author?: lyztroy lyztroy@bupt.edu.cn
 * @Date?: 2022-06-12 10?:58?:32
 * @LastEditors: lyztroy lyztroy@bupt.edu.cn
 * @LastEditTime: 2022-06-12 16:05:20
 * @FilePath?: /visualNotes/src/utils/diff.ts
 * @Description?: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置?: https?://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

export interface Position {
  x?: number;
  y?: number;
}

export interface Data {
  type?: string;
  text?: string;
  label?: string;
  remark?: string;
}

export interface Element {
  id?: string;
  type: string;
  position?: Position;
  data?: Data;
  source?: string;
  sourceHandle?: any;
  target?: string;
  targetHandle?: string;
}

// 节点数量差异
export const nodeNumDiff = (interEls: Element[], standEls: Element[]) => {
  
};

// 连线数量差异
export const edgeNumDiff = (interEls: Element[], standEls: Element[]) => {

};

//比较线条的输入输出
export const lineInOutDiff = (interEls: Element[], standEls: Element[]) => {};

//记录同类型节点个数
export const findNodeNum = (els: Element[]) => {
  let map = new Map();
  els.map((item) => {
    if (item.source) {
      return;
    } else {
      if (map.get(item.type)) {
        map.set(item.type, map.get(item.type) + 1);
      } else {
        map.set(item.type, 1);
      }
    }
  });
  return map;
};
//记录同类型连线数量
export const findEdgeNum = (els: Element[]) => {
  let map = new Map();
  els.map((item) => {
    if (!item.source) {
      return;
    } else {
      if (map.get(item.type)) {
        map.set(item.type, map.get(item.type) + 1);
      } else {
        map.set(item.type, 1);
      }
    }
  });
  return map;
};
//记录连线的输入输出
export const findLineSource = (els: Element[]) => {
  let arr: { type: string; source: string; target: string }[] = [];
  els.map((item) => {
    if (!item.source) {
      return;
    } else {
      const sourceNode = els.filter((itm) => itm.id === item.source);
      const targeNode = els.filter((itm) => itm.id === item.target);
      const temp = {
        type: item.type,
        text: item.data?.text,
        source: sourceNode[0]?.type ?? "",
        sourceText: sourceNode[0]?.data?.label ?? "",
        target: targeNode[0]?.type ?? "",
        targetText: targeNode[0]?.data?.label ?? "",
      };
      arr.push(temp);
    }
  });
  return arr;
};
